
import java.sql.ResultSet;

/*
 * dlgHighScore.java
 *
 * Created on 18 April 2010, 22:21
 */
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;



/**
 *
 * @author  Administrator
 */
public class dlgHighScore extends javax.swing.JDialog {
    
    /** Creates new form dlgHighScore */
    public dlgHighScore(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        try {
            initComponents();
            ResultSet rs = DB.GetType();
            while (rs.next()) {
                cmbType.addItem(rs.getInt("width")+"X"+rs.getInt("height"));
            }
        } catch (SQLException ex) {
            Logger.getLogger(dlgHighScore.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        cmbType = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblHS = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Loại:");

        cmbType.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTypeActionPerformed(evt);
            }
        });

        tblHS.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Tên", "Điểm", "Ngày chơi", "Thời gian chơi"
            }
        ));
        jScrollPane1.setViewportView(tblHS);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(62, 62, 62)
                .add(jLabel1)
                .add(49, 49, 49)
                .add(cmbType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 158, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(111, Short.MAX_VALUE))
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(cmbType, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(22, 22, 22)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 227, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTypeActionPerformed
        try {
            // TODO add your handling code here:
            ResultSet rs = DB.GetHS(cmbType.getSelectedItem().toString());
            DefaultTableModel model=(DefaultTableModel) tblHS.getModel();
            model.getDataVector().clear();
            while (rs.next()) {
                Vector v = new Vector();
                v.addElement(rs.getString("username"));
                v.addElement(rs.getInt("mark"));
                v.addElement(rs.getString("_date"));
                v.addElement(rs.getString("_time"));
                model.addRow(v);
            }
        } catch (SQLException ex) {
            Logger.getLogger(dlgHighScore.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cmbTypeActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                dlgHighScore dialog = new dlgHighScore(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tblHS;
    // End of variables declaration//GEN-END:variables
    
}
